www.gusucode.com > 24Beta 虚拟主机版 1.0.0 Beta源码程序 > 24Beta 虚拟主机版 1.0.0 Beta源码程序/24Beta-1.0.0-vhost/protected/modules/admin/controllers/FriendlinkController.php

    <?php

class FriendlinkController extends CController
{
	public function actionPartners()
	{
	    $links = FriendLink::model()->getFriendLinks(FriendLink::TYPE_COOP);
		$this->render('list', array('links' => $links));
	}
	
    public function actionContributer()
	{
		$links = FriendLink::model()->getFriendLinks(FriendLink::TYPE_CONTRIBUTOR);
		$this->render('list', array('links' => $links));
	}
	
    public function actionFriend()
	{
		$links = FriendLink::model()->getFriendLinks(FriendLink::TYPE_NORMAL);
		$this->render('list', array('links' => $links));
	}
	
    public function actionCreate()
	{
	    if (app()->request->isPostRequest) {
	        $name = trim($_POST['name']);
	        $homepage = trim($_POST['homepage']);
	        
	        if (empty($name) || empty($homepage)) {
	            $prompt['result'] = false;
	            $prompt['note'][] = array('text' => '友情链接名称和网站地址不能为空');
	            $prompt['note'][] = array('text' => '重新添加友情链接', 'url'=>url('admin/friendlink/create'));
	            $prompt['note'][] = array('text' => '返回重试', 'url'=>'javascript:history.back();');
	            $this->render('create', array('prompt'=>$prompt));
	            exit(0);
	        }
	        
	        $c = FriendLink::model()->findByAttributes(array('name' => $name));
	        if ($c !== null) {
	            $prompt['result'] = false;
                $prompt['note'][] = array('text' => $name . '&nbsp;友情链接已经存在');
	            $prompt['note'][] = array('text' => '添加新的友情链接', 'url'=>url('admin/friendlink/create'));
	        } else {
    	        $fl = new Friendlink();
    	        $fl->name = $name;
    	        $fl->type = $_POST['type'];
    	        $fl->homepage = $_POST['homepage'];
    	        $fl->isvalid = $_POST['isvalid'];
    	        $fl->logo = $_POST['logo'];
    	        $fl->desc = $_POST['desc'];
    	        $result = $fl->save();
    	        
    	        if ($result) {
    	            $prompt['result'] = true;
                    $prompt['note'][] = array('text' => $name . '&nbsp;友情链接添加成功');
	                $prompt['note'][] = array('text' => '继续添加友情链接', 'url'=>url('admin/friendlink/create'));
    	        } else {
    	            $prompt['result'] = false;
                    $prompt['note'][] = array('text' => $name . '&nbsp;友情链接添加失败');
	                $prompt['note'][] = array('text' => '重新添加友情链接', 'url'=>url('admin/friendlink/create'));
	                $prompt['note'][] = array('text' => '返回重试', 'url'=>'javascript:history.back();');
    	        }
	        }
	    }
	    $this->render('create', array('prompt'=>$prompt));
	}
	

    public function actionUpdate()
	{
	    if (app()->request->isPostRequest) {
	        foreach ($_POST['name'] as $fid => $v) {
	            $attributes = array(
	                'order_id' => $_POST['order_id'][$fid],
	                'name' => $_POST['name'][$fid],
	            	'homepage' => $_POST['homepage'][$fid],
	                'logo' => $_POST['logo'][$fid],
	                'desc' => $_POST['desc'][$fid],
	            );
	            $result = FriendLink::model()->updateByPk($fid, $attributes);
	            if ($result === false) {
	                throw new CHttpException(400, $v . ' 更新错误...');
	            }
	        }
	        $this->redirect(app()->request->urlReferrer);
	    }
	}
}